from flask_restful import Resource, reqparse
from flask import request
from . import format_color, checkoutArgs
from app.api.services.service_theme import ServiceTheme


class ApiThemeList(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        super(ApiThemeList, self).__init__()

    def get(self):
        # args = self.reqparse.parse_args(strict=True)
        return ServiceTheme().list_theme()


class ApiThemeUpdate(Resource):
    def __init__(self):
        self.reqparse = reqparse.RequestParser()
        self.reqparse.add_argument(
            'backgroundColor', type=format_color, help='backgroundColor颜色字符传输错误')
        self.reqparse.add_argument(
            'textColor', type=format_color, help='textColor颜色字符传输错误')
        super(ApiThemeUpdate, self).__init__()

    def post(self, id):
        args = self.reqparse.parse_args(strict=True)
        args_filter = checkoutArgs(args)
        return ServiceTheme().update_theme(id, **args_filter)
